﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理后台登录</title>

    <!--图标库 可无视-->
    <link rel='stylesheet' href='../css/font-awesome.min.css'>

    <!--核心样式-->
    <link rel="stylesheet" href="../css/admin/style.css">

</head>
<body>

<div class="container">
    <div class="card"></div>
    <div class="card">
        <form>
            <h1 class="title">用户登录</h1>
            <div class="input-container">
                <input type="text" id="username" name="username" required="required"/>
                <label for="username">用户名</label>
                <div class="bar"></div>
            </div>
            <div class="input-container">
                <input type="password" id="psw" name="password" required="required"/>
                <label for="psw">密码</label>
                <div class="bar"></div>
            </div>
            <div class="button-container">
                <button type="button" onclick="login()"><span>登录</span></button>
            </div>
        </form>
    </div>
    <div class="card alt">
        <div class="toggle"></div>
    </div>
</div>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="../js/plugins/layer/layer.min.js"></script>

<script>
    function login() {
        var data = {}
        data['username'] = $('#username').val()
        data['password'] = $('#psw').val()
        $.ajax({
            url: 'admin_login',
            data: data,
            dataType: 'json',
            success: function (res) {
                if (res.code != 200) {
                    layer.msg(res.error)
                } else {
                    document.cookie = 'token=' + res.data.token + "; path=/";
                    window.location = 'index'
                }
            },
        });
    }
</script>
</body>
</html>

